<template>
	<el-table
	    :data="batchTableData"
	    style="width: 100%"
      height=100%
      v-loading="loading"
      element-loading-text="数据正在加载中..."
      :header-cell-style="{background:'#eef1f6',color:'#606266'}"
		>

	    <el-table-column
	      label="批次名称"
        align=center
	      width="180">
	      <template slot-scope="scope">
	        <span style="margin-left: 10px">{{ scope.row.batchName }}</span>
	      </template>
	    </el-table-column>
		<el-table-column
		  label="学校评审开始日期"
		  align=center
		 >
		  <template slot-scope="scope">
		    <i class="el-icon-time"></i>
		    <span style="margin-left: 10px">{{ firstOrSecondStart(scope.row) }}</span>
		  </template>
		</el-table-column>
		<el-table-column
		  label="学校评审结束日期"
		  align=center
		  >
		  <template slot-scope="scope">
		    <i class="el-icon-time"></i>
		    <span style="margin-left: 10px">{{ firstOrSecondEnd(scope.row) }}</span>
		  </template>
		</el-table-column>
		</el-table-column>
	    <el-table-column
	      label="批次类别"
		  align=center
	      >
	      <template slot-scope="scope">
	        <span >{{ scope.row.levelName }}</span>
	      </template>
	    </el-table-column>
	    <el-table-column
		align=center
		label="操作">
	      <template slot-scope="scope">
	        <el-button
	          size="mini"
			  type="success"
	          @click="enterBatch(scope.$index, scope.row)">进入</el-button>
	      </template>
	    </el-table-column>
	  </el-table>

</template>

<script>
	export default {
		created() {
      this.teacherinfo = this.$store.state.info
			this.getAllData()
			this.getNowDate()
      console.log(this.$store.state.info)
		},
	    data() {
	      return {
       teacherinfo:'',
			 //batch表数据
	     batchTableData:[],
			//yyyy-mm-dd型日期
			nowDate:'',
			//加载状态
			loading:true
	      }
	    },
      computed:{
        firstOrSecondStart(){
          return function(row){
            if(row.phaseExpertStart!=null){
              return row.phaseSchoolSecondStart
            }else{
              return row.phaseSchoolFirstStart
            }
          }
        },
        firstOrSecondEnd(){
          return function(row){
            if(row.phaseExpertEnd!=null){
              return row.phaseSchoolSecondEnd
            }else{
              return row.phaseSchoolFirstEnd
            }
          }
        }
      },
	    methods: {
	      enterBatch(index, row) {
          if(row.status==1){
            this.$router.push({path:'/uniProjectAudit',query:{batch_id:row.batchId}})
          }
          if(row.status==3)
          {
            this.$router.push({path:'/uniSecondProjectAudit',query:{batch_id:row.batchId}})
          }
	        console.log(index, row);
	      },
		  //获得数据Axios
		  getAllData(){
        var tempAllBatchInfo,state
			  this.$api.batch.getAllBatch({})
			  .then((response)=>{
				  tempAllBatchInfo=response.data.data.filter((item)=>{
					return  new Date(this.nowDate) >=  Date.parse(item.phaseSchoolFirstStart)
					&& new Date(this.nowDate) <= Date.parse(item.phaseSchoolFirstEnd) && item.status==1 || new Date(this.nowDate) >=  Date.parse(item.phaseSchoolSecondStart)
					&& new Date(this.nowDate) <= Date.parse(item.phaseSchoolSecondEnd) && item.status==3
				  })
          console.log(tempAllBatchInfo)
          this.batchTableData=tempAllBatchInfo
				  this.loading=false
			  })
		  }
		  ,
		  //得到当前日期
		  getNowDate(){
		    var nowDate = new Date();
		    var year = nowDate.getFullYear();
		    var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1): nowDate.getMonth() + 1;
		    var day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate
		     .getDate();
		    var dateStr = year + "-" + month + "-" + day;
		    this.nowDate=dateStr
		    console.log("现在日期："+this.nowDate)
		  },
	    }
	  }
</script>

<style scoped>

</style>
